//
//  YZYLoginView.h
//  YZYSDKManagerDemo
//
//  Created by 赵隆杰 on 2024/6/7.
//

#import "YZYLoginView.h"
#import "Masonry.h"
#import "YZYSDKManagerHeader.h"
#import "YZYSaccountStore.h"
#import "ZCFunDataFormat.h"
#import "ZCNetworkManager.h"

@interface YZYLoginView ()<UITextFieldDelegate>
{
    dispatch_source_t _timer;
}
@property (nonatomic, strong) UIButton *coverView;

@property (nonatomic, strong) UIImageView *backbg_login;
@property (nonatomic ,strong) UIButton *login_changeBtn0;
@property (nonatomic ,strong) UIButton *login_changeBtn1;
@property (nonatomic, strong) UIScrollView *login_scrollview;
@property (nonatomic ,strong) UITextField *login_username;
@property (nonatomic ,strong) UITextField *login_password;
@property (nonatomic ,strong) UIButton *login_pwd_agreeBtn;
@property (nonatomic ,strong) UITextField *login_mobilePhone;
@property (nonatomic ,strong) UITextField *login_verificationCode;
@property (nonatomic ,strong) UIButton *login_verificationBtn;
@property (nonatomic ,strong) UIButton *login_ver_agreeBtn;
@property (nonatomic, assign) NSInteger currentSelected;//当前选中哪种登录方式 0密码登录（默认） 1验证码登录

@property (nonatomic, strong) UIImageView *backbg_register;
@property (nonatomic ,strong) UITextField *register_username;
@property (nonatomic ,strong) UITextField *register_password;
@property (nonatomic ,strong) UITextField *register_mobilePhone;
@property (nonatomic ,strong) UITextField *register_verificationCode;
@property (nonatomic ,strong) UIButton *register_verificationBtn;

@property (nonatomic, strong) UIImageView *backbg_forget;
@property (nonatomic ,strong) UITextField *forget_mobilePhone;
@property (nonatomic ,strong) UITextField *forget_verificationCode;
@property (nonatomic ,strong) UIButton *forget_verificationBtn;
@property (nonatomic ,strong) UITextField *forget_password;
@property (nonatomic ,strong) UITextField *forget_comfig_password;

@property (nonatomic ,strong) UITextField *firstResponderTextF;//记录将要编辑的输入框
@property (nonatomic, assign) CGFloat self_Height;//保存原始的view高度

@end

@implementation YZYLoginView

- (instancetype)init {
    if (self == [super init]) {
        
        [self initUI_backbg_login];
        [self initUIWithRegister];
        [self initUIWithForget];
        
        //监听键盘展示和隐藏的通知
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
        
    }
    return self;
}

- (void)initUI_backbg_login {
    UIImageView *backbg = [[UIImageView alloc] init];
    backbg.userInteractionEnabled = YES;
    backbg.backgroundColor = [UIColor whiteColor];
    backbg.layer.masksToBounds = YES;
    backbg.layer.cornerRadius = 4;
    [self addSubview:backbg];
    backbg.frame = CGRectMake(0, 0, popupW, popupH_login);
    self.backbg_login = backbg;
    
    UIView *titleView = [[UIView alloc] init];
    [backbg addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(backbg);
        make.height.mas_equalTo(50);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont boldSystemFontOfSize:24];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"用户登录";
    [titleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(titleView);
    }];
    
    UIView *changeView = [[UIView alloc] init];
    [backbg addSubview:changeView];
    [changeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backbg).offset(25);
        make.right.equalTo(backbg).offset(-25);
        make.top.equalTo(titleView.mas_bottom);
        make.height.mas_equalTo(40);
    }];
    UIButton *changeBtn0 = [[UIButton alloc] init];
    changeBtn0.tag = 0;
    [changeBtn0 setTitle:(YZY_IS_APPLE?@"密码登录":@"验证码登录") forState:UIControlStateNormal];
    [changeBtn0 setTitleColor:yzy_themeColor forState:UIControlStateSelected];
    [changeBtn0 setTitleColor:yzy_labelColor forState:UIControlStateNormal];
    [changeBtn0 setBackgroundImage:[[YZYSaccountStore sharedInstance] imageWithColor:[UIColor colorWithRed:233/255.0 green:249/255.0 blue:250/255.0 alpha:1.0]] forState:UIControlStateSelected];
    [changeBtn0 setBackgroundImage:[[YZYSaccountStore sharedInstance] imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];
    [changeBtn0 setBackgroundImage:[[YZYSaccountStore sharedInstance] imageWithColor:[UIColor whiteColor]] forState:UIControlStateHighlighted];
    changeBtn0.layer.borderColor = yzy_themeColor.CGColor;
    changeBtn0.layer.cornerRadius = 5;
    changeBtn0.layer.borderWidth = 1;
    changeBtn0.layer.masksToBounds = YES;
    [changeBtn0 addTarget:self action:@selector(login_changeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [changeView addSubview:changeBtn0];
    [changeBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(changeView);
        make.right.equalTo(changeView.mas_centerX);
    }];
    self.login_changeBtn0 = changeBtn0;
    
    UIButton *changeBtn1 = [[UIButton alloc] init];
    changeBtn1.tag = 1;
    [changeBtn1 setTitle:(YZY_IS_APPLE?@"验证码登录":@"密码登录") forState:UIControlStateNormal];
    [changeBtn1 setTitleColor:yzy_themeColor forState:UIControlStateSelected];
    [changeBtn1 setTitleColor:yzy_labelColor forState:UIControlStateNormal];
    [changeBtn1 setBackgroundImage:[[YZYSaccountStore sharedInstance] imageWithColor:[UIColor colorWithRed:233/255.0 green:249/255.0 blue:250/255.0 alpha:1.0]] forState:UIControlStateSelected];
    [changeBtn1 setBackgroundImage:[[YZYSaccountStore sharedInstance] imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];
    [changeBtn1 setBackgroundImage:[[YZYSaccountStore sharedInstance] imageWithColor:[UIColor whiteColor]] forState:UIControlStateHighlighted];
    changeBtn1.layer.borderColor = yzy_themeColor.CGColor;
    changeBtn1.layer.cornerRadius = 5;
    changeBtn1.layer.borderWidth = 1;
    changeBtn1.layer.masksToBounds = YES;
    [changeBtn1 addTarget:self action:@selector(login_changeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [changeView addSubview:changeBtn1];
    [changeBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(changeView);
        make.left.equalTo(changeView.mas_centerX);
    }];
    self.login_changeBtn1 = changeBtn1;
    
    UIScrollView *scrollview = [[UIScrollView alloc] init];
    scrollview.contentSize = CGSizeMake(popupW * 2, 0);
    scrollview.scrollEnabled = NO;
    [backbg addSubview:scrollview];
    [scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(backbg);
        make.top.equalTo(changeView.mas_bottom);
    }];
    self.login_scrollview = scrollview;
    
    //index 0 表示在前面
    if (YZY_IS_APPLE) {
        [self initUI_backbg_login_passwordForchangeView:changeView withIndex:0];
        [self initUI_backbg_login_verificationForchangeView:changeView withIndex:1];
    } else {
        [self initUI_backbg_login_verificationForchangeView:changeView withIndex:0];
        [self initUI_backbg_login_passwordForchangeView:changeView withIndex:1];
    }
    
    self.currentSelected = 0;
}

- (void)initUIWithRegister {
    UIImageView *backbg = [[UIImageView alloc] init];
    backbg.userInteractionEnabled = YES;
    backbg.backgroundColor = [UIColor whiteColor];
    backbg.layer.masksToBounds = YES;
    backbg.layer.cornerRadius = 4;
    [self addSubview:backbg];
    backbg.frame = CGRectMake(0, 0, popupW, popupH_login);
    self.backbg_register = backbg;
    self.backbg_register.hidden = YES;
    
    UIView *titleView = [[UIView alloc] init];
    [backbg addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(backbg);
        make.height.mas_equalTo(50);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont boldSystemFontOfSize:24];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"用户注册";
    [titleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(titleView);
    }];
    UIImageView *back_image = [[UIImageView alloc] init];
    back_image.image = [[YZYSaccountStore sharedInstance] getImage:@"arrow_back"];
    [titleView addSubview:back_image];
    [back_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(14);
        make.height.mas_equalTo(20);
        make.left.equalTo(titleView).offset(20);
        make.centerY.equalTo(titleView);
    }];
    UIButton *backBtn = [[UIButton alloc] init];
    backBtn.tag = 100;
    [titleView addSubview:backBtn];
    [backBtn addTarget:self action:@selector(register_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(44);
        make.left.centerY.equalTo(titleView);
    }];
    
    UITextField *mobilePhone = [[UITextField alloc] init];
    mobilePhone.placeholder = @"请输入手机号";
    mobilePhone.keyboardType = UIKeyboardTypePhonePad;
    mobilePhone.delegate = self;
    mobilePhone.font = [UIFont systemFontOfSize:16];
    mobilePhone.borderStyle = UITextBorderStyleRoundedRect;
    mobilePhone.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:mobilePhone];
    [mobilePhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backbg).offset(25);
        make.centerX.equalTo(backbg);
        make.top.equalTo(titleView.mas_bottom);
        make.height.mas_equalTo(40);
    }];
    self.register_mobilePhone = mobilePhone;
    
    UIButton *verificationBtn = [[UIButton alloc] init];
    verificationBtn.tag = 101;
    verificationBtn.layer.cornerRadius = 5;
    verificationBtn.layer.masksToBounds = YES;
    verificationBtn.backgroundColor = yzy_themeColor;
    verificationBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [verificationBtn addTarget:self action:@selector(register_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:verificationBtn];
    [verificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(mobilePhone.mas_bottom).offset(5);
        make.height.mas_equalTo(40);
        make.right.equalTo(mobilePhone);
        make.width.mas_equalTo(100);
    }];
    self.register_verificationBtn = verificationBtn;
    
    UITextField *verificationCode = [[UITextField alloc] init];
    verificationCode.placeholder = @"请输入验证码";
    verificationCode.keyboardType = UIKeyboardTypeNumberPad;
    verificationCode.delegate = self;
    verificationCode.font = [UIFont systemFontOfSize:16];
    verificationCode.borderStyle = UITextBorderStyleRoundedRect;
    verificationCode.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:verificationCode];
    [verificationCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(verificationBtn);
        make.left.equalTo(mobilePhone);
        make.right.equalTo(verificationBtn.mas_left).offset(-10);
    }];
    self.register_verificationCode = verificationCode;
    
    UITextField *username = [[UITextField alloc] init];
    username.placeholder = @"请设置用户名";
    username.delegate = self;
    username.font = [UIFont systemFontOfSize:16];
    username.borderStyle = UITextBorderStyleRoundedRect;
    username.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:username];
    [username mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backbg).offset(25);
        make.centerX.equalTo(backbg);
        make.top.equalTo(verificationCode.mas_bottom).offset(5);
        make.height.mas_equalTo(40);
    }];
    self.register_username = username;
    
    UITextField *password = [[UITextField alloc] init];
    password.placeholder = @"请设置密码";
    password.delegate = self;
    password.font = [UIFont systemFontOfSize:16];
    password.borderStyle = UITextBorderStyleRoundedRect;
    password.returnKeyType = UIReturnKeyDone;
    password.secureTextEntry = YES;
    [backbg addSubview:password];
    [password mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(username);
        make.top.equalTo(username.mas_bottom).offset(5);
    }];
    self.register_password = password;
    
    UIButton *registerBtn = [[UIButton alloc] init];
    registerBtn.tag = 102;
    registerBtn.layer.cornerRadius = 5;
    registerBtn.layer.masksToBounds = YES;
    registerBtn.backgroundColor = yzy_themeColor;
    [registerBtn setTitle:@"注  册" forState:UIControlStateNormal];
    [registerBtn addTarget:self action:@selector(register_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:registerBtn];
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.left.equalTo(mobilePhone);
        make.centerX.equalTo(backbg);
        make.top.equalTo(password.mas_bottom).offset(10);
    }];
    
    //用户协议
    UITextView *agreementTextView = [[UITextView alloc] init];
    [backbg addSubview:agreementTextView];
    [agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.centerX.equalTo(backbg);
        make.top.equalTo(registerBtn.mas_bottom);
        make.left.equalTo(backbg).offset(20);
    }];
    
    agreementTextView.font = [UIFont systemFontOfSize:10];
    //    agreementTextView.textContainerInset = UIEdgeInsetsMake((40/2 - agreementTextView.font.lineHeight/2), 0, 0, 0);
    agreementTextView.text = @"注册即表示同意《用户协议》和《隐私协议》";
    agreementTextView.editable = NO;        //必须禁止输入，否则点击将弹出输入键盘
    agreementTextView.scrollEnabled = NO;
    agreementTextView.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1.0];
    agreementTextView.linkTextAttributes = @{NSForegroundColorAttributeName: yzy_themeColor};
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:agreementTextView.text];
    [attributedString addAttribute:NSLinkAttributeName
                             value:YZY_User_Agreement
                             range:NSMakeRange(7, 6)];
    [attributedString addAttribute:NSLinkAttributeName
                             value:YZY_Privacy_Agreement
                             range:NSMakeRange(14, 6)];
    agreementTextView.attributedText = attributedString;
}

- (void)initUIWithForget {
    UIImageView *backbg = [[UIImageView alloc] init];
    backbg.userInteractionEnabled = YES;
    backbg.backgroundColor = [UIColor whiteColor];
    backbg.layer.masksToBounds = YES;
    backbg.layer.cornerRadius = 4;
    [self addSubview:backbg];
    backbg.frame = CGRectMake(0, 0, popupW, popupH_login);
    self.backbg_forget = backbg;
    self.backbg_forget.hidden = YES;
    
    UIView *titleView = [[UIView alloc] init];
    [backbg addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(backbg);
        make.height.mas_equalTo(50);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont boldSystemFontOfSize:24];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"重置密码";
    [titleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(titleView);
    }];
    UIImageView *back_image = [[UIImageView alloc] init];
    back_image.image = [[YZYSaccountStore sharedInstance] getImage:@"arrow_back"];
    [titleView addSubview:back_image];
    [back_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(14);
        make.height.mas_equalTo(20);
        make.left.equalTo(titleView).offset(20);
        make.centerY.equalTo(titleView);
    }];
    UIButton *backBtn = [[UIButton alloc] init];
    backBtn.tag = 1000;
    [titleView addSubview:backBtn];
    [backBtn addTarget:self action:@selector(forget_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(44);
        make.left.centerY.equalTo(titleView);
    }];
    
    UITextField *mobilePhone = [[UITextField alloc] init];
    mobilePhone.placeholder = @"请输入手机号";
    mobilePhone.keyboardType = UIKeyboardTypePhonePad;
    mobilePhone.delegate = self;
    mobilePhone.font = [UIFont systemFontOfSize:16];
    mobilePhone.borderStyle = UITextBorderStyleRoundedRect;
    mobilePhone.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:mobilePhone];
    [mobilePhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backbg).offset(25);
        make.centerX.equalTo(backbg);
        make.top.equalTo(titleView.mas_bottom);
        make.height.mas_equalTo(40);
    }];
    self.forget_mobilePhone = mobilePhone;
    
    UIButton *verificationBtn = [[UIButton alloc] init];
    verificationBtn.tag = 1001;
    verificationBtn.layer.cornerRadius = 5;
    verificationBtn.layer.masksToBounds = YES;
    verificationBtn.backgroundColor = yzy_themeColor;
    verificationBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [verificationBtn addTarget:self action:@selector(forget_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:verificationBtn];
    [verificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(mobilePhone.mas_bottom).offset(5);
        make.height.mas_equalTo(40);
        make.right.equalTo(mobilePhone);
        make.width.mas_equalTo(100);
    }];
    self.forget_verificationBtn = verificationBtn;
    
    UITextField *verificationCode = [[UITextField alloc] init];
    verificationCode.placeholder = @"请输入验证码";
    verificationCode.keyboardType = UIKeyboardTypeNumberPad;
    verificationCode.delegate = self;
    verificationCode.font = [UIFont systemFontOfSize:16];
    verificationCode.borderStyle = UITextBorderStyleRoundedRect;
    verificationCode.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:verificationCode];
    [verificationCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(verificationBtn);
        make.left.equalTo(mobilePhone);
        make.right.equalTo(verificationBtn.mas_left).offset(-10);
    }];
    self.forget_verificationCode = verificationCode;
    
    UITextField *password = [[UITextField alloc] init];
    password.placeholder = @"请输入新密码";
    password.delegate = self;
    password.font = [UIFont systemFontOfSize:16];
    password.borderStyle = UITextBorderStyleRoundedRect;
    password.returnKeyType = UIReturnKeyDone;
    password.secureTextEntry = YES;
    [backbg addSubview:password];
    [password mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(mobilePhone);
        make.top.equalTo(verificationCode.mas_bottom).offset(5);
    }];
    self.forget_password = password;
    
    UITextField *comfig_password = [[UITextField alloc] init];
    comfig_password.placeholder = @"再次输入新密码";
    comfig_password.delegate = self;
    comfig_password.font = [UIFont systemFontOfSize:16];
    comfig_password.borderStyle = UITextBorderStyleRoundedRect;
    comfig_password.returnKeyType = UIReturnKeyDone;
    comfig_password.secureTextEntry = YES;
    [backbg addSubview:comfig_password];
    [comfig_password mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(password);
        make.top.equalTo(password.mas_bottom).offset(5);
    }];
    self.forget_comfig_password = comfig_password;
    
    UIButton *comfigBtn = [[UIButton alloc] init];
    comfigBtn.tag = 1002;
    comfigBtn.layer.cornerRadius = 5;
    comfigBtn.layer.masksToBounds = YES;
    comfigBtn.backgroundColor = yzy_themeColor;
    [comfigBtn setTitle:@"确  认" forState:UIControlStateNormal];
    [comfigBtn addTarget:self action:@selector(forget_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:comfigBtn];
    [comfigBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.left.equalTo(comfig_password);
        make.centerX.equalTo(backbg);
        make.top.equalTo(comfig_password.mas_bottom).offset(10);
    }];
    
}

- (void)initUI_backbg_login_passwordForchangeView:(UIView *)login_changeView withIndex:(int)index {
    UIImageView *backbg = [[UIImageView alloc] init];
    backbg.userInteractionEnabled = YES;
    [self.login_scrollview addSubview:backbg];
    backbg.frame = CGRectMake(index*popupW, 0, popupW, popupH_login);
    
    UITextField *mobilePhone = [[UITextField alloc] init];
    mobilePhone.placeholder = @"请输入手机号";
    mobilePhone.keyboardType = UIKeyboardTypePhonePad;
    mobilePhone.delegate = self;
    mobilePhone.font = [UIFont systemFontOfSize:16];
    mobilePhone.borderStyle = UITextBorderStyleRoundedRect;
    mobilePhone.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:mobilePhone];
    [mobilePhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backbg).offset(25);
        make.centerX.equalTo(backbg);
        make.top.equalTo(backbg).offset(10);
        make.height.mas_equalTo(40);
    }];
    self.login_username = mobilePhone;
    
    UITextField *password = [[UITextField alloc] init];
    password.placeholder = @"请输入密码";
    password.delegate = self;
    password.font = [UIFont systemFontOfSize:16];
    password.borderStyle = UITextBorderStyleRoundedRect;
    password.returnKeyType = UIReturnKeyDone;
    password.secureTextEntry = YES;
    [backbg addSubview:password];
    [password mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(mobilePhone);
        make.top.equalTo(mobilePhone.mas_bottom).offset(10);
    }];
    self.login_password = password;
    
    UIButton *loginBtn = [[UIButton alloc] init];
    loginBtn.tag = 10;
    loginBtn.layer.cornerRadius = 5;
    loginBtn.layer.masksToBounds = YES;
    loginBtn.backgroundColor = yzy_themeColor;
    [loginBtn setTitle:@"登  录" forState:UIControlStateNormal];
    [loginBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.left.equalTo(mobilePhone);
        make.centerX.equalTo(backbg);
        make.top.equalTo(password.mas_bottom).offset(15);
    }];
    
    UIButton *registerBtn = [[UIButton alloc] init];
    registerBtn.tag = 11;
    [registerBtn setTitle:@"立即注册" forState:UIControlStateNormal];
    [registerBtn setTitleColor:yzy_themeColor forState:UIControlStateNormal];
    registerBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [registerBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:registerBtn];
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(31);
        make.left.equalTo(loginBtn);
        make.top.equalTo(loginBtn.mas_bottom);
    }];
    
    UIButton *forgetBtn = [[UIButton alloc] init];
    forgetBtn.tag = 12;
    [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    [forgetBtn setTitleColor:yzy_themeColor forState:UIControlStateNormal];
    forgetBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [forgetBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:forgetBtn];
    [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(registerBtn);
        make.right.equalTo(loginBtn);
        make.top.equalTo(loginBtn.mas_bottom);
    }];
    
    UIView *agreeView = [[UIView alloc] init];
    [backbg addSubview:agreeView];
    [agreeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(31);
        make.centerX.equalTo(backbg);
        make.top.equalTo(forgetBtn.mas_bottom);
        make.left.equalTo(backbg).offset(20);
    }];
    
    UIButton *agreeBtn = [[UIButton alloc] init];
    agreeBtn.tag = 13;
    agreeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    agreeBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    agreeBtn.imageView.contentMode = UIViewContentModeScaleToFill;
    [agreeBtn setImage:[[YZYSaccountStore sharedInstance] getImage:@"agreeBtn_unselected"] forState:UIControlStateNormal];
    [agreeBtn setImage:[[YZYSaccountStore sharedInstance] getImage:@"agreeBtn_selected"] forState:UIControlStateSelected];
    [agreeBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [agreeView addSubview:agreeBtn];
    [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(22);
        make.left.centerY.equalTo(agreeView);
    }];
    agreeBtn.selected = NO;
    //用户协议
    UITextView *agreementTextView = [[UITextView alloc] init];
    [agreeView addSubview:agreementTextView];
    [agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(agreeView);
        make.height.equalTo(agreeView);
        make.left.equalTo(agreeBtn.mas_right);
        make.centerY.equalTo(agreeView);
    }];
    
    agreementTextView.font = [UIFont systemFontOfSize:10];
    agreementTextView.textContainerInset = UIEdgeInsetsMake((31/2 - agreementTextView.font.lineHeight/2), 0, 0, 0);
    agreementTextView.text = @"我已阅读并同意《用户协议》和《隐私协议》";
    agreementTextView.editable = NO;        //必须禁止输入，否则点击将弹出输入键盘
    agreementTextView.scrollEnabled = NO;
    agreementTextView.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1.0];
    agreementTextView.linkTextAttributes = @{NSForegroundColorAttributeName: yzy_themeColor};
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:agreementTextView.text];
    [attributedString addAttribute:NSLinkAttributeName
                             value:YZY_User_Agreement
                             range:NSMakeRange(7, 6)];
    [attributedString addAttribute:NSLinkAttributeName
                             value:YZY_Privacy_Agreement
                             range:NSMakeRange(14, 6)];
    agreementTextView.attributedText = attributedString;
    self.login_pwd_agreeBtn = agreeBtn;
    if ([[YZYSaccountStore sharedInstance] getAgreeSelected]) {
        self.login_pwd_agreeBtn.selected = YES;
    }
}

- (void)initUI_backbg_login_verificationForchangeView:(UIView *)changeView  withIndex:(int)index {
    UIView *backbg = [[UIView alloc] init];
    backbg.userInteractionEnabled = YES;
    [self.login_scrollview addSubview:backbg];
    backbg.frame = CGRectMake(index*popupW, 0, popupW, popupH_login);
    
    UITextField *mobilePhone = [[UITextField alloc] init];
    mobilePhone.placeholder = @"请输入手机号";
    mobilePhone.keyboardType = UIKeyboardTypePhonePad;
    mobilePhone.delegate = self;
    mobilePhone.font = [UIFont systemFontOfSize:16];
    mobilePhone.borderStyle = UITextBorderStyleRoundedRect;
    mobilePhone.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:mobilePhone];
    [mobilePhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backbg).offset(25);
        make.centerX.equalTo(backbg);
        make.top.equalTo(backbg).offset(10);
        make.height.mas_equalTo(40);
    }];
    self.login_mobilePhone = mobilePhone;
    
    UIButton *verificationBtn = [[UIButton alloc] init];
    verificationBtn.tag = 20;
    verificationBtn.layer.cornerRadius = 5;
    verificationBtn.layer.masksToBounds = YES;
    verificationBtn.backgroundColor = yzy_themeColor;
    verificationBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [verificationBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:verificationBtn];
    [verificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(mobilePhone.mas_bottom).offset(10);
        make.height.mas_equalTo(40);
        make.right.equalTo(mobilePhone);
        make.width.mas_equalTo(100);
    }];
    self.login_verificationBtn = verificationBtn;
    
    UITextField *verificationCode = [[UITextField alloc] init];
    verificationCode.placeholder = @"请输入验证码";
    verificationCode.keyboardType = UIKeyboardTypeNumberPad;
    verificationCode.delegate = self;
    verificationCode.font = [UIFont systemFontOfSize:16];
    verificationCode.borderStyle = UITextBorderStyleRoundedRect;
    verificationCode.returnKeyType = UIReturnKeyDone;
    [backbg addSubview:verificationCode];
    [verificationCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(verificationBtn);
        make.left.equalTo(mobilePhone);
        make.right.equalTo(verificationBtn.mas_left).offset(-10);
    }];
    self.login_verificationCode = verificationCode;
    
    UIButton *loginBtn = [[UIButton alloc] init];
    loginBtn.tag = 21;
    loginBtn.layer.cornerRadius = 5;
    loginBtn.layer.masksToBounds = YES;
    loginBtn.backgroundColor = yzy_themeColor;
    [loginBtn setTitle:@"登  录" forState:UIControlStateNormal];
    [loginBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backbg addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.left.equalTo(mobilePhone);
        make.centerX.equalTo(backbg);
        make.top.equalTo(verificationCode.mas_bottom).offset(15);
    }];
    
    UIView *agreeView = [[UIView alloc] init];
    [backbg addSubview:agreeView];
    [agreeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.centerX.equalTo(backbg);
        make.top.equalTo(loginBtn.mas_bottom).offset(5);
        make.left.equalTo(backbg).offset(20);
    }];
    
    UIButton *agreeBtn = [[UIButton alloc] init];
    agreeBtn.tag = 22;
    agreeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    agreeBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    agreeBtn.imageView.contentMode = UIViewContentModeScaleToFill;
    [agreeBtn setImage:[[YZYSaccountStore sharedInstance] getImage:@"agreeBtn_unselected"] forState:UIControlStateNormal];
    [agreeBtn setImage:[[YZYSaccountStore sharedInstance] getImage:@"agreeBtn_selected"] forState:UIControlStateSelected];
    [agreeBtn addTarget:self action:@selector(login_didBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [agreeView addSubview:agreeBtn];
    [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(22);
        make.left.centerY.equalTo(agreeView);
    }];
    agreeBtn.selected = NO;
    //用户协议
    UITextView *agreementTextView = [[UITextView alloc] init];
    [agreeView addSubview:agreementTextView];
    [agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(agreeView);
        make.height.equalTo(agreeView);
        make.left.equalTo(agreeBtn.mas_right);
        make.centerY.equalTo(agreeView);
    }];
    
    agreementTextView.font = [UIFont systemFontOfSize:10];
    agreementTextView.textContainerInset = UIEdgeInsetsMake((40/2 - agreementTextView.font.lineHeight/2), 0, 0, 0);
    agreementTextView.text = @"我已阅读并同意《用户协议》和《隐私协议》";
    agreementTextView.editable = NO;        //必须禁止输入，否则点击将弹出输入键盘
    agreementTextView.scrollEnabled = NO;
    agreementTextView.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1.0];
    agreementTextView.linkTextAttributes = @{NSForegroundColorAttributeName: yzy_themeColor};
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:agreementTextView.text];
    [attributedString addAttribute:NSLinkAttributeName
                             value:YZY_User_Agreement
                             range:NSMakeRange(7, 6)];
    [attributedString addAttribute:NSLinkAttributeName
                             value:YZY_Privacy_Agreement
                             range:NSMakeRange(14, 6)];
    agreementTextView.attributedText = attributedString;
    self.login_ver_agreeBtn = agreeBtn;
    if ([[YZYSaccountStore sharedInstance] getAgreeSelected]) {
        self.login_ver_agreeBtn.selected = YES;
    }
}

- (void)setCurrentSelected:(NSInteger)currentSelected {
    if (currentSelected == 0) {
        self.login_changeBtn0.layer.borderWidth = 1;
        self.login_changeBtn1.layer.borderWidth = 0;
        self.login_changeBtn0.selected = YES;
        self.login_changeBtn1.selected = NO;
    } else {
        self.login_changeBtn0.layer.borderWidth = 0;
        self.login_changeBtn1.layer.borderWidth = 1;
        self.login_changeBtn0.selected = NO;
        self.login_changeBtn1.selected = YES;
    }
}

#pragma mark - 切换按钮事件
- (void)login_changeBtnClick:(UIButton *)button {
    self.currentSelected = button.tag;
    [self stopTimerForButton:self.login_verificationBtn];
    [self endEditing:YES];
    if (button.tag == 0) {
        [self.login_scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
    } else {
        [self.login_scrollview setContentOffset:CGPointMake(popupW, 0) animated:YES];
    }
}

#pragma mark - 点击按钮事件
- (void)login_didBtnClick:(UIButton *)button {
    [self endEditing:YES];
    [self login_didBtnClickTag:button.tag];
}
- (void)login_didBtnClickTag:(NSInteger)tag {
    if (tag == 10) {
        //密码登录登录按钮
        NSString *username = self.login_username.text;
        NSString *password = self.login_password.text;
        
        if ([ZCFunDataFormat isBlankString:username]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:password]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"密码为空"];
            return;
        }
        if (self.login_pwd_agreeBtn.selected == NO) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"请先勾选同意用户协议和隐私协议"];
            return;
        }
        NSDictionary *params = [NSDictionary dictionary];
        params = @{
            @"gameId": [ZCFunDataFormat GetPlatformGameID],
            @"account": username,
            @"password": password,
            @"channelNo": [ZCFunDataFormat GetChanneNo]
        };
        [ZCNetworkManager postWithURL:YZY_AppendUrl(YZY_skip_login) Params:params success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            NSDictionary *resultDic = [NSDictionary dictionaryWithDictionary:surperdic[@"data"]];
            if ([surpercode isEqualToString:@"200"]) {
                self.loginViewBlock(2, resultDic, self);
                [self closeView];
            }
        } failure:^(NSString *error) {
        }];
    } else if (tag == 11) {
        //密码登录立即注册按钮
        self.backbg_login.hidden = YES;
        self.backbg_register.hidden = NO;
        self.backbg_forget.hidden = YES;
    } else if (tag == 12) {
        //密码登录忘记密码按钮
        self.backbg_login.hidden = YES;
        self.backbg_register.hidden = YES;
        self.backbg_forget.hidden = NO;
    } else if (tag == 13) {
        //密码登录协议按钮
        self.login_pwd_agreeBtn.selected = !self.login_pwd_agreeBtn.selected;
        self.login_ver_agreeBtn.selected = self.login_pwd_agreeBtn.selected;
        [[YZYSaccountStore sharedInstance] saveAgreeSelected:self.login_pwd_agreeBtn.selected];
    } else if (tag == 20) {
        //验证码登录验证码按钮
        NSString *phone = self.login_mobilePhone.text;
        if ([ZCFunDataFormat isBlankString:phone]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        NSString *url = [NSString stringWithFormat:@"%@/%@", YZY_getCode, phone];
        [ZCNetworkManager getWithURL:YZY_AppendUrl(url) Params:nil success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            if ([surpercode isEqualToString:@"200"]) {
                [self startTimerForButton:self.login_verificationBtn];
            }
        } failure:^(NSString *error) {
        }];
    } else if (tag == 21) {
        //验证码登录登录按钮
        NSString *phone = self.login_mobilePhone.text;
        NSString *verificationCode = self.login_verificationCode.text;
        
        if ([ZCFunDataFormat isBlankString:phone]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:verificationCode]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"验证码为空"];
            return;
        }
        if (self.login_ver_agreeBtn.selected == NO) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"请先勾选同意用户协议和隐私协议"];
            return;
        }
        
        [self stopTimerForButton:self.login_verificationBtn];
          
        NSDictionary *params = [NSDictionary dictionary];
        params = @{
            @"gameId": [ZCFunDataFormat GetPlatformGameID],
            @"phone": phone,
            @"code": verificationCode,
            @"channelNo": [ZCFunDataFormat GetChanneNo]
        };
        [ZCNetworkManager postWithURL:YZY_AppendUrl(YZY_loginByPhone) Params:params success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            NSDictionary *resultDic = [NSDictionary dictionaryWithDictionary:surperdic[@"data"]];
            if ([surpercode isEqualToString:@"200"]) {
                self.loginViewBlock(2, resultDic, self);
                [self closeView];
            }
        } failure:^(NSString *error) {
        }];
    } else if (tag == 22) {
        //验证码登录协议按钮
        self.login_ver_agreeBtn.selected = !self.login_ver_agreeBtn.selected;
        self.login_pwd_agreeBtn.selected = self.login_ver_agreeBtn.selected;
        [[YZYSaccountStore sharedInstance] saveAgreeSelected:self.login_ver_agreeBtn.selected];
    }
    
}
- (void)register_didBtnClick:(UIButton *)button {
    [self endEditing:YES];
    [self register_didBtnClickTag:button.tag];
}
- (void)register_didBtnClickTag:(NSInteger)tag {
    if (tag == 100) {
        //用户注册返回按钮
        self.backbg_login.hidden = NO;
        self.backbg_register.hidden = YES;
        self.backbg_forget.hidden = YES;
        //注册成功后需要清除
        self.register_username.text = @"";
        self.register_password.text = @"";
        self.register_mobilePhone.text = @"";
        self.register_verificationCode.text = @"";
        [self stopTimerForButton:self.register_verificationBtn];
        
    } else if (tag == 101) {
        //用户注册验证码按钮
        NSString *phone = self.register_mobilePhone.text;
        if ([ZCFunDataFormat isBlankString:phone]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        NSString *url = [NSString stringWithFormat:@"%@/%@", YZY_getCode, phone];
        [ZCNetworkManager getWithURL:YZY_AppendUrl(url) Params:nil success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            if ([surpercode isEqualToString:@"200"]) {
                [self startTimerForButton:self.register_verificationBtn];
            }
        } failure:^(NSString *error) {
        }];
        
    } else if (tag == 102) {
        //用户注册注册按钮
        NSString *phone = self.register_mobilePhone.text;
        NSString *verificationCode = self.register_verificationCode.text;
        NSString *username = self.register_username.text;
        NSString *password = self.register_password.text;
        
        if ([ZCFunDataFormat isBlankString:phone]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:verificationCode]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"验证码为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:username]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"用户名为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:password]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"密码为空"];
            return;
        }
        
        [self stopTimerForButton:self.register_verificationBtn];
        
        NSDictionary *params = [NSDictionary dictionary];
        params = @{
            @"gameId": [ZCFunDataFormat GetPlatformGameID],
            @"phone": phone,
            @"code": verificationCode,
            @"nickName": username,
            @"password": password,
            @"channelNo": [ZCFunDataFormat GetChanneNo]
        };
        [ZCNetworkManager postWithURL:YZY_AppendUrl(YZY_skip_register) Params:params success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            if ([surpercode isEqualToString:@"200"]) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    //注册完成返回登录界面
                    [self register_didBtnClickTag:100];
                    //注册成功后传递用户名和密码
                    self.login_username.text = phone;
                    self.login_password.text = password;
                });
            }
        } failure:^(NSString *error) {
        }];
    }
}

- (void)forget_didBtnClick:(UIButton *)button {
    [self endEditing:YES];
    [self forget_didBtnClickTag:button.tag];
}
- (void)forget_didBtnClickTag:(NSInteger)tag {
    if (tag == 1000) {
        //忘记密码返回按钮
        self.backbg_login.hidden = NO;
        self.backbg_register.hidden = YES;
        self.backbg_forget.hidden = YES;
        
        //确认成功后需要清除
        self.forget_mobilePhone.text = @"";
        self.forget_password.text = @"";
        self.forget_comfig_password.text = @"";
        self.forget_verificationCode.text = @"";
        [self stopTimerForButton:self.forget_verificationBtn];
    } else if (tag == 1001) {
        //忘记密码验证码按钮
        NSString *phone = self.forget_mobilePhone.text;
        if ([ZCFunDataFormat isBlankString:phone]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        NSString *url = [NSString stringWithFormat:@"%@/%@", YZY_getCode, phone];
        [ZCNetworkManager getWithURL:YZY_AppendUrl(url) Params:nil success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            if ([surpercode isEqualToString:@"200"]) {
                [self startTimerForButton:self.forget_verificationBtn];
            }
        } failure:^(NSString *error) {
        }];
    } else if (tag == 1002) {
        //忘记密码确认按钮
        NSString *phone = self.forget_mobilePhone.text;
        NSString *verificationCode = self.forget_verificationCode.text;
        NSString *password = self.forget_password.text;
        NSString *comfig_password = self.forget_comfig_password.text;
        
        if ([ZCFunDataFormat isBlankString:phone]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"手机号为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:verificationCode]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"验证码为空"];
            return;
        }
        if ([ZCFunDataFormat isBlankString:password]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"新密码为空"];
            return;
        }
        if (![password isEqualToString:comfig_password]) {
            [[YZYSaccountStore sharedInstance] makeToastFromWindow:@"两次密码不一致"];
            return;
        }
        [self stopTimerForButton:self.forget_verificationBtn];
        
        NSDictionary *params = [NSDictionary dictionary];
        params = @{
            @"gameId": [ZCFunDataFormat GetPlatformGameID],
            @"phone": phone,
            @"code": verificationCode,
            @"password": password,
            @"towPassword": password
        };
        [ZCNetworkManager postWithURL:YZY_AppendUrl(YZY_skip_resetPassword) Params:params success:^(id responseObject) {
            NSDictionary *surperdic = (NSDictionary *)responseObject;
            NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
            if ([surpercode isEqualToString:@"200"]) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    //确认完成返回登录界面
                    [self forget_didBtnClickTag:1000];
                    //确认成功后传递手机号和密码
                    self.login_username.text = phone;
                    self.login_password.text = password;
                });
            }
        } failure:^(NSString *error) {
        }];
    }
}

/**
 *  开始倒计时
 */
- (void)startTimerForButton:(UIButton *)button {
    __block int timeout = 59; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //倒计时结束，关闭
            dispatch_source_cancel(self->_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置（倒计时结束后调用）
                [button setTitle:@"获取验证码" forState:UIControlStateNormal];
                //设置可点击
                button.userInteractionEnabled = YES;
                button.backgroundColor = yzy_themeColor;
                
            });
        } else {
            int seconds = timeout % 60;
            NSString *strTime = [NSString stringWithFormat:@"%d", seconds];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                NSLog(@"____%@",strTime);
                [button setTitle:[NSString stringWithFormat:@"重新获取(%@')",strTime] forState:UIControlStateNormal];
                //设置不可点击
                button.userInteractionEnabled = NO;
                button.backgroundColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0];
            });
            timeout--;
        }
    });
    
    dispatch_resume(_timer);
}

/**
 *  停止倒计时
 */
- (void)stopTimerForButton:(UIButton *)button {
    if (_timer) {
        //销毁定时器
        dispatch_source_cancel(_timer);
    }
    //获取验证码按钮恢复初始状态
    [button setTitle:@"获取验证码" forState:UIControlStateNormal];
    //设置可点击
    button.userInteractionEnabled = YES;
    button.backgroundColor = yzy_themeColor;
}

- (void)show {
    [[YZYSaccountStore sharedInstance] getCurrentWindowWithCompletion:^(UIWindow *window) {
        if (window) {
            UIButton *coverView = [[UIButton alloc] init];
            coverView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f];
            [coverView addTarget:self action:@selector(coverViewClick) forControlEvents:UIControlEventTouchUpInside];
            self.coverView = coverView;
            coverView.frame = window.bounds;
            
            UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
            UIVisualEffectView *visualView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
            visualView.alpha = 0.0;
            [coverView addSubview:visualView];
            visualView.frame = coverView.frame;
            
            [window addSubview:coverView];
            
            self.frame = CGRectMake(0, 0, popupW, popupH_login);
            self.layer.cornerRadius = 12.0f;
            self.center = CGPointMake(window.center.x, window.center.y);
            if (![ZCFunDataFormat GetIsLandscape]) {
                self.center = CGPointMake(window.center.x, window.center.y - 10);
            }
            self.self_Height = self.frame.origin.y;
            [window addSubview:self];
        }
    }];
}

- (void)coverViewClick {
    [self endEditing:YES];
}

- (void)closeView {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.coverView removeFromSuperview];
        [self removeFromSuperview];
    });
}


- (void)dealloc{
    //移除键盘通知监听者
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if ([self.firstResponderTextF isFirstResponder])[self.firstResponderTextF resignFirstResponder];
}
#pragma maek UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    self.firstResponderTextF = textField;//当将要开始编辑的时候，获取当前的textField
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

#pragma mark : UIKeyboardWillShowNotification/UIKeyboardWillHideNotification
- (void)keyboardWillShow:(NSNotification *)notification{
    CGRect rect = [self.firstResponderTextF.superview convertRect:self.firstResponderTextF.frame toView:self];//获取相对于self.view的位置
    NSDictionary *userInfo = [notification userInfo];
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];//获取弹出键盘的fame的value值
    CGRect keyboardRect = [aValue CGRectValue];
    keyboardRect = [self convertRect:keyboardRect fromView:self.window];//获取键盘相对于self.view的frame ，传window和传nil是一样的
    CGFloat keyboardTop = keyboardRect.origin.y;
    NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘弹出动画时间值
    NSTimeInterval animationDuration = [animationDurationValue doubleValue];
    if (keyboardTop < CGRectGetMaxY(rect)) {//如果键盘盖住了输入框
        CGFloat gap = keyboardTop - CGRectGetMaxY(rect) - 10;//计算需要网上移动的偏移量（输入框底部离键盘顶部为10的间距）
        __weak typeof(self)weakSelf = self;
        [UIView animateWithDuration:animationDuration animations:^{
            weakSelf.frame = CGRectMake(weakSelf.frame.origin.x, gap, weakSelf.frame.size.width, weakSelf.frame.size.height);
        }];
    }
    
}
- (void)keyboardWillHide:(NSNotification *)notification{
    NSDictionary *userInfo = [notification userInfo];
    NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘隐藏动画时间值
    NSTimeInterval animationDuration = [animationDurationValue doubleValue];
    if (self.frame.origin.y < 0) {//如果有偏移，当影藏键盘的时候就复原
        __weak typeof(self)weakSelf = self;
        [UIView animateWithDuration:animationDuration animations:^{
            weakSelf.frame = CGRectMake(weakSelf.frame.origin.x, weakSelf.self_Height, weakSelf.frame.size.width, weakSelf.frame.size.height);
        }];
    }
}

@end
